package com.pengshun;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.pengshun.modules.api.huanxin.service.HuanXinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class Test {

    //入参格式化
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    //出参格式化
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm")
    private Date d;

    //加法 add()函数     减法subtract()函数
//乘法multiply()函数    除法divide()函数
    ////前提为a、b均不能为null
//if(a.compareTo(b) == -1){
//    System.out.println("a小于b");
//}
//
//if(a.compareTo(b) == 0){
//    System.out.println("a等于b");
//}
//
//if(a.compareTo(b) == 1){
//    System.out.println("a大于b");
//}
//
//if(a.compareTo(b) > -1){
//    System.out.println("a大于等于b");
//}
//
//if(a.compareTo(b) < 1){
//    System.out.println("a小于等于b");
    public static String getAutoTime(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        Calendar currentCalendar = Calendar.getInstance();
        currentCalendar.set(Calendar.HOUR_OF_DAY, 0);
        currentCalendar.set(Calendar.MINUTE, 0);
        currentCalendar.set(Calendar.SECOND, 0);
        currentCalendar.set(Calendar.MILLISECOND, 0);
        long dateL = calendar.getTimeInMillis();
        long nowL = currentCalendar.getTimeInMillis();
        if (dateL < nowL - 1296000000L) { // 比15天前还早
            if (calendar.get(Calendar.YEAR) == currentCalendar.get(Calendar.YEAR)) { // 在今年
                return getDate(date);
            } else {
                return getDateOneYear(date);
            }
        } else if (dateL < nowL - 172800000L) { // 比今天0时还早48小时以上
            return ((nowL - dateL) / 86400000L) + "天前";
        } else if (dateL < nowL - 86400000L) { // 比今天0时还早24小时以上
            return "前天 " + getTime(date);
        } else if (dateL < nowL) { // 比今天0时还早
            return "昨天 " + getTime(date);
        } else if (dateL < nowL + 21600000L) { // 今天6点前
            return "凌晨 " + getTime(date);
        } else if (dateL < nowL + 43200000L) { // 今天12点前
            return "早上 " + getTime(date);
        } else if (dateL < nowL + 64800000L) { // 今天18点前
            return "下午 " + getTime(date);
        } else if (dateL < nowL + 86400000L) { // 明天0时前
            return "晚上 " + getTime(date);
        } else if (dateL < nowL + 172800000L) { // 晚今天0时48小时内
            return "明天 " + getTime(date);
        } else if (dateL < nowL + 259200000L) { // 晚今天0时72小时内
            return "后天 " + getTime(date);
        } else {
            return getDateOneYear(date);
        }
    }
    @Autowired
    private HuanXinService huanXinService;

    public static void main(String[] args) throws ParseException {
        String aa="2021-04-29 08:30";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());
        System.out.println(getAutoTime(sdf.parse(aa)));
    }

    public static String getBaseDate(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:00", Locale.getDefault());
        return sdf.format(date);
    }
    public static String getDateOneYear(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日", Locale.getDefault());
        return sdf.format(date);
    }

    public static String getDate(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日", Locale.getDefault());
        return sdf.format(date);
    }

    public static String getTime(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm", Locale.getDefault());
        return sdf.format(date);
    }

    public static String getWeek(int value) {
        switch (value) {
            case 1:
                return "周日";
            case 2:
                return "周一";
            case 3:
                return "周二";
            case 4:
                return "周三";
            case 5:
                return "周四";
            case 6:
                return "周五";
            default:
                return "周六";
        }
    }
//        DrawTableImg cg = new DrawTableImg();
//        String tableData1[][] = {{"8月31日", "累计用户数", "目标值", "完成进度", "时间进度", "进度差异"}, {"掌厅客户端（户）", "469281", "1500000", "31.2%", "33.6%", "-2.4%"}};
//        String[][] tableData2 = {{"8月31日（户）", "新增用户数", "日访问量", "累计用户数", "环比上月"},
//                {"合肥和巢湖", "469281", "1500000", "31.2%", "33.6%"},
//                {"芜湖", "469281", "1500000", "31.2%", "33.6%"},
//                {"蚌埠", "469281", "1500000", "31.2%", "33.6%"},
//                {"淮南", "469281", "1500000", "31.2%", "33.6%"},
//                {"马鞍山", "469281", "1500000", "31.2%", "33.6%"},
//                {"淮北", "469281", "1500000", "31.2%", "33.6%"}};
//        cg.myGraphicsGeneration(tableData2, "c:\\myPic.jpg");


//        String res[] = "254-1-42".split("-");
//        System.out.println(res[1]);
//
//        System.out.println(res[2]);
//        if (res[1].equals(BillType.BILL_TYPE_ONE.toString())) {
//            System.out.println(111);
//        }

    }


